/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package job.manager.icefaces.validator;

import job.manager.client.wb.ext.*;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author Administrator
 */
public class EmailValidator implements Validator {

    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        String email = (String)value;
        FacesMessage msg = new FacesMessage();
        if( !email.isEmpty() ){
            boolean isValid = EmailValidationWebService.ValidateEmail(email);
            if(isValid)
                return;
            msg.setDetail(" Email felaktig");
            msg.setSummary("Email felaktig");
        }else {
            msg.setDetail(" Email får inte vara tomt");
            msg.setSummary("Email får inte vara tomt");
        }
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ValidatorException(msg);
    }

}
